/*
 * Copyright (c) 2018. czmc All Rights Reserved.
 * Author: czmc
 * Email: zxc6355533@163.com
 * Encoding: UTF-8
 */

package top.stime21.myneighbours.module.settings

import android.os.Bundle
import android.text.TextUtils
import android.view.View
import com.orhanobut.logger.Logger
import kotlinx.android.synthetic.main.activity_feedback.*
import kotlinx.android.synthetic.main.include_header.*
import me.drakeet.materialdialog.MaterialDialog
import top.stime21.framework.mvp.BaseActivity
import top.stime21.myneighbours.R
import top.stime21.myneighbours.api.ApiManager
import top.stime21.myneighbours.base.io_main

class FeedbackActivity : BaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_feedback)
        tv_title.text = "我的反馈"
        btn_back.setOnClickListener({ finish() })
        btn_commit.setOnClickListener {
            var email = et_email.text.toString();
            var content = et_content.text.toString()
            if (TextUtils.isEmpty(email)) {
                showToast("请填写联系人方式")
                return@setOnClickListener
            }
            if (TextUtils.isEmpty(content)) {
                showToast("请填写反馈内容")
                return@setOnClickListener
            }
            ApiManager.ins().dataApi.feedback(email, content).io_main().subscribe({ s ->
                if (s.isSuccess) {
                    val dialog = MaterialDialog(this@FeedbackActivity).setTitle("")
                    dialog.setTitle("反馈成功")
                            .setMessage("感谢您的反馈")
                            .setPositiveButton("确定", View.OnClickListener {
                                dialog.dismiss()
                                finish()
                            })
                    dialog.show()
                } else {
                    showToast("很抱歉,上传失败")
                }

            }, { t ->
                Logger.e(t.toString())
                showToast("服务出问题了..")
            })
        }
    }
}